<template>
    <div>
        <van-nav-bar
            style="background-color: #dfb390;"
            left-text="确认订单"
            left-arrow
            @click-left="edsc"
        />
        <van-cell-group inset style="margin: 0.1rem;">
            <van-cell is-link @click="onclick" icon="location-o">
                <!-- 使用 title 插槽来自定义标题 -->
                <template #title>
                    <div style="display: flex;">
                        <span>{{ address.name }}</span>
                        <span>{{ address.tel }}</span>
                        <br />
                    </div>
                    <span>{{ address.address }}</span>
                </template>
            </van-cell>
        </van-cell-group>
        <van-card
            v-if="orderNum"
            :num="value"
            :price="(orderNum.shopPrice / 100).toFixed(2)"
            desc
            :title="orderNum.name"
            :thumb="imgurl + orderNum.defaultImg"
        />
        <van-card
            v-else
            :num="value"
            :price="(product.shopPrice / 100).toFixed(2)"
            desc
            :title="product.name"
            :thumb="imgurl + product.defaultImg"
        />
        <van-cell-group>
            <van-cell title="购买数量">
                <van-stepper v-model="value" />
            </van-cell>
            <van-cell title="配送方式" is-link>快递 免邮</van-cell>
            <van-cell title="开具发票" is-link>本次不开发票</van-cell>
        </van-cell-group>
        <div style="margin:20px 0">
            <van-cell-group inset>
                <van-cell title="电子钱包支付">
                    <van-radio-group v-model="radio">
                        <van-radio name="1" checked-color="#ee0a24"></van-radio>
                    </van-radio-group>
                </van-cell>
            </van-cell-group>
        </div>
        <van-submit-bar
            v-if="orderNum"
            :price="orderNum.shopPrice * value"
            button-text="提交订单"
            @submit="submit()"
        />
        <van-submit-bar
            v-else
            :price="product.shopPrice * value"
            button-text="提交订单"
            @submit="submit()"
        />
    </div>
</template>

<script>
import roofVue from "../other/roof.vue";
export default {
    data() {
        return {
            getparment: null,
            address: {},
            orderNum: null,
            value: 1,
            radio: "1",
            // setproduct: null
            price: 0,
            product: null,
            goods: null
        }
    },
    components: {
        roofVue,
    },
    methods: {
        onclick() {
            this.$router.push('/address')
            this.Sto.Session.set("bools", 1)
        },
        // 退出
        edsc() {
            this.Sto.Session.remove("bools");
            // this.$router.replace()
            history.go(-2);
        },
        submit() {
            // this.value.
            console.log(this.value * this.product.shopPrice);
            this.$post(this.url2 + "/account/recharge", {
                userId: this.$store.state.user.id,
                amount: -(this.value * this.product.shopPrice)
            }).then(res => {
                console.log(res);
                if (res.errorCode == '0') {
                    this.$toast("支付成功")
                    this.$router.push("/chenggong")
                }
            })
        },
        getlist() {
            // catalog/product/details
            this.$post(this.url2 + "/product/detail", {
                id: this.orderNum.id,
            }).then((res) => {
                console.log(res);
                if (res.errorCode == "0") {
                    this.product = res.data;
                    console.log(this.product)
                    this.value = this.goods.selectedNum
                    // this.sku.price = res.data.shopPrice / 100;
                    // this.sku.stock_num = res.data.quantity;
                    // this.goods.picture = this.imgurl + res.data.defaultImg;
                    // res.data.skuList.map(nus => {
                    //     nus.s1 = nus.optionValueKeyGroup.split("_")[0]
                    //     nus.s2 = nus.optionValueKeyGroup.split("_")[1]
                    //     nus.stock_num = nus.quantity
                    //     delete nus.quantity
                    //     delete nus.optionValueKeyGroup
                    //     this.sku.list.push(nus)
                    // })
                    // console.log(this.sku.list);

                }
            });
        },

    },
    created() {
        this.address = this.Sto.Session.get("payaddress");
        console.log(this.address);
        if (!this.address) {
            console.log(1);
            this.$dialog({ message: "你还没有添加地址请先添加地址" })
            this.$router.push('/address')
            this.Sto.Session.set("bools", 1)
            return
        }
        this.orderNum = this.Sto.Session.get("orderNum")
        this.goods = this.Sto.Session.get("goods")
        console.log(this.orderNum);
        console.log(this.goods);
        this.getlist()
    },
    watch: {
        radio() {
            console.log(this.radio);
        }
    }
};
</script>

<style  scoped>
</style>
